<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">


<meta name="google-site-verification" content="E9deYnivN5MuHMuIfiMZZfS0alv-d_0UjcwjBL79lGU" />



<meta name="baidu-site-verification" content="iHYWJxscwD" />










<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="true" />








  <meta name="baidu-site-verification" content="true" />







  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Python,量化投资,编程难题,MIT,列表,字符串,数据压缩," />










<meta name="description" content="试了一圈，还是用基于问题学习吧。看《Programming for the Puzzled》，有中译版的。我看的还是英文版的。MIT还有同名的课程。我看的是b站上搬运的:https:&#x2F;&#x2F;b23.tv&#x2F;5vyRZk课程主页： https:&#x2F;&#x2F;ocw.mit.edu&#x2F;courses&#x2F;electrical-engineering-and-computer-science&#x2F;6-s095-programmi">
<meta property="og:type" content="article">
<meta property="og:title" content="量化投资学习笔记46——通过问题学算法:01你们将会完全一致(you will all conform)">
<meta property="og:url" content="https://zwdnet.github.io/2020/05/01/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B046%E2%80%94%E2%80%94%E9%80%9A%E8%BF%87%E9%97%AE%E9%A2%98%E5%AD%A6%E7%AE%97%E6%B3%95-01%E4%BD%A0%E4%BB%AC%E5%B0%86%E4%BC%9A%E5%AE%8C%E5%85%A8%E4%B8%80%E8%87%B4-you-will-all-conform/index.html">
<meta property="og:site_name" content="赵瑜敏的口腔医学专业学习博客">
<meta property="og:description" content="试了一圈，还是用基于问题学习吧。看《Programming for the Puzzled》，有中译版的。我看的还是英文版的。MIT还有同名的课程。我看的是b站上搬运的:https:&#x2F;&#x2F;b23.tv&#x2F;5vyRZk课程主页： https:&#x2F;&#x2F;ocw.mit.edu&#x2F;courses&#x2F;electrical-engineering-and-computer-science&#x2F;6-s095-programmi">
<meta property="og:locale">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg">
<meta property="article:published_time" content="2020-05-01T04:31:12.000Z">
<meta property="article:modified_time" content="2020-08-30T05:52:04.000Z">
<meta property="article:author" content="赵瑜敏">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="量化投资">
<meta property="article:tag" content="编程难题">
<meta property="article:tag" content="MIT">
<meta property="article:tag" content="列表">
<meta property="article:tag" content="字符串">
<meta property="article:tag" content="数据压缩">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zwdnet.github.io/2020/05/01/量化投资学习笔记46——通过问题学算法-01你们将会完全一致-you-will-all-conform/"/>





  <title>量化投资学习笔记46——通过问题学算法:01你们将会完全一致(you will all conform) | 赵瑜敏的口腔医学专业学习博客</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">赵瑜敏的口腔医学专业学习博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zwdnet.github.io/2020/05/01/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B046%E2%80%94%E2%80%94%E9%80%9A%E8%BF%87%E9%97%AE%E9%A2%98%E5%AD%A6%E7%AE%97%E6%B3%95-01%E4%BD%A0%E4%BB%AC%E5%B0%86%E4%BC%9A%E5%AE%8C%E5%85%A8%E4%B8%80%E8%87%B4-you-will-all-conform/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="赵瑜敏的口腔医学专业学习博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">量化投资学习笔记46——通过问题学算法:01你们将会完全一致(you will all conform)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-01T04:31:12+00:00">
                2020-05-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" itemprop="url" rel="index">
                    <span itemprop="name">量化投资</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.3k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  9
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>试了一圈，还是用基于问题学习吧。<br>看《Programming for the Puzzled》，有中译版的。我看的还是英文版的。MIT还有同名的课程。我看的是b站上搬运的:<a target="_blank" rel="noopener" href="https://b23.tv/5vyRZk">https://b23.tv/5vyRZk</a><br>课程主页： <a target="_blank" rel="noopener" href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s095-programming-for-the-puzzled-january-iap-2018/index.htm%EF%BC%8C%E4%B8%8A%E9%9D%A2%E6%9C%89%E4%BB%A3%E7%A0%81%E5%92%8C%E7%BB%83%E4%B9%A0%E8%A7%A3%E7%AD%94%E3%80%82">https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s095-programming-for-the-puzzled-january-iap-2018/index.htm，上面有代码和练习解答。</a><br>主要训练的是将解决方案实现为代码。在写代码以前先确定代码的行为。<br>问题描述:一群球迷戴着球帽排成一排准备入场，他们戴的帽子有两个方向。你要通过对某个位置或者某个位置区间的球迷发布命令让其翻转帽子方向，问题是如何用最少的命令来达到这一目的。一个更难的问题，如何在开始的时候就生成所有的命令?<br>自己先做一下:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># coding:utf-8</span></span><br><span class="line"><span class="comment"># 01.you will all conform</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取最少的命令数</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">minCommand</span>(<span class="params">cap</span>):</span></span><br><span class="line">    n = <span class="built_in">len</span>(cap)</span><br><span class="line">    <span class="comment"># 先把&quot;F&quot;变成&quot;B&quot;</span></span><br><span class="line">    minTimesB = <span class="number">0</span></span><br><span class="line">    bF = <span class="literal">False</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(n):</span><br><span class="line">        <span class="keyword">if</span> cap[i] == <span class="string">&quot;F&quot;</span>:</span><br><span class="line">            bF = <span class="literal">True</span></span><br><span class="line">            <span class="keyword">if</span> i == n-<span class="number">1</span>:</span><br><span class="line">                minTimesB += <span class="number">1</span></span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        <span class="keyword">if</span> bF == <span class="literal">True</span>:</span><br><span class="line">            minTimesB += <span class="number">1</span></span><br><span class="line">        bF = <span class="literal">False</span></span><br><span class="line">    <span class="comment"># 再把&quot;B&quot;变成&quot;F&quot;</span></span><br><span class="line">    minTimesF = <span class="number">0</span></span><br><span class="line">    bB = <span class="literal">False</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(n):</span><br><span class="line">        <span class="keyword">if</span> cap[i] == <span class="string">&quot;B&quot;</span>:</span><br><span class="line">            bB = <span class="literal">True</span></span><br><span class="line">            <span class="keyword">if</span> i == n-<span class="number">1</span>:</span><br><span class="line">                minTimesF += <span class="number">1</span></span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        <span class="keyword">if</span> bB == <span class="literal">True</span>:</span><br><span class="line">            minTimesF += <span class="number">1</span></span><br><span class="line">        bB = <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">min</span>(minTimesB, minTimesF)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    <span class="comment"># 穷举法</span></span><br><span class="line">    cap = [<span class="string">&quot;F&quot;</span>, <span class="string">&quot;F&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;F&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;F&quot;</span>, <span class="string">&quot;F&quot;</span>, <span class="string">&quot;B&quot;</span>, <span class="string">&quot;F&quot;</span>]</span><br><span class="line">    result = minCommand(cap)</span><br><span class="line">    print(result)</span><br></pre></td></tr></table></figure>
<p>能得到正确结果，但是用了两次循环，而且代码有点繁琐。作者给出的方案是先根据输入得到一个区间的列表，包括每个区间的帽子方向。注意最后一个元素，其并不是以帽子方向翻转为结束的。<br>最坏的情况下，要喊n/2次（n为偶数）或n/2+1次（n为奇数）命令。<br>来看看作者给出的解法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 书中第一个解法，先找出相应区间</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pleaseConform</span>(<span class="params">caps</span>):</span></span><br><span class="line">    start = forward = backward = <span class="number">0</span></span><br><span class="line">    intervals = []</span><br><span class="line">    n = <span class="built_in">len</span>(caps)</span><br><span class="line">    minNum = n</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, n):</span><br><span class="line">        <span class="comment"># 帽子方向变了，区间改变</span></span><br><span class="line">        <span class="keyword">if</span> caps[start] != caps[i]:</span><br><span class="line">            intervals.append((start, i-<span class="number">1</span>, caps[start]))</span><br><span class="line">            <span class="keyword">if</span> caps[start] == <span class="string">&quot;F&quot;</span>:</span><br><span class="line">                forward += <span class="number">1</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                backward += <span class="number">1</span></span><br><span class="line">            start = i</span><br><span class="line">    <span class="comment"># 处理最后一个区间</span></span><br><span class="line">    intervals.append((start, <span class="built_in">len</span>(caps)-<span class="number">1</span>, caps[start]))</span><br><span class="line">    <span class="keyword">if</span> caps[start] == <span class="string">&quot;F&quot;</span>:</span><br><span class="line">        forward += <span class="number">1</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        backward += <span class="number">1</span></span><br><span class="line">    <span class="keyword">if</span> forward &lt; backward:</span><br><span class="line">        flip = <span class="string">&quot;F&quot;</span></span><br><span class="line">        minNum = forward</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        flip = <span class="string">&quot;B&quot;</span></span><br><span class="line">        minNum = backward</span><br><span class="line">    <span class="keyword">for</span> t <span class="keyword">in</span> intervals:</span><br><span class="line">        <span class="keyword">if</span> t[<span class="number">2</span>] == flip:</span><br><span class="line">            print(<span class="string">&quot;在位置&#123;&#125;到&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br><span class="line">    <span class="keyword">return</span> minNum</span><br></pre></td></tr></table></figure>
<p>运行结果:<br>在位置2到4的人，翻转你的帽子<br>在位置6到8的人，翻转你的帽子<br>在位置11到11的人，翻转你的帽子<br>3<br>比我的要长，不过清楚多了，而且只用遍历列表一遍。当然还遍历了一遍区间列表，在极端的情况下还是等于遍历了两遍。然后是用tuple来记录区间起始点及帽子方向的，要会用tuple，不要只会list。<br>下面尝试代码优化。尽量缩短代码，更小的程序通常更有效率，bug也要更少。<br>为了避免对结尾的特殊判断，可以在输入的caps列表里加一个“结束标志”<br>caps = caps + [“END”]<br>这样对最后一个区间的特殊处理就不用了。另外一个好处是输入空列表程序也不会崩溃了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 书中第二个解法，对解法一的优化</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pleaseConform2</span>(<span class="params">caps</span>):</span></span><br><span class="line">    start = forward = backward = <span class="number">0</span></span><br><span class="line">    intervals = []</span><br><span class="line">    <span class="comment"># 在数据末尾增加末尾标志</span></span><br><span class="line">    caps = caps + [<span class="string">&quot;END&quot;</span>]</span><br><span class="line">    n = <span class="built_in">len</span>(caps)</span><br><span class="line">    minNum = n</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, n):</span><br><span class="line">        <span class="comment"># 帽子方向变了，区间改变</span></span><br><span class="line">        <span class="keyword">if</span> caps[start] != caps[i]:</span><br><span class="line">            intervals.append((start, i-<span class="number">1</span>, caps[start]))</span><br><span class="line">            <span class="keyword">if</span> caps[start] == <span class="string">&quot;F&quot;</span>:</span><br><span class="line">                forward += <span class="number">1</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                backward += <span class="number">1</span></span><br><span class="line">            start = i</span><br><span class="line">    <span class="keyword">if</span> forward &lt; backward:</span><br><span class="line">        flip = <span class="string">&quot;F&quot;</span></span><br><span class="line">        minNum = forward</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        flip = <span class="string">&quot;B&quot;</span></span><br><span class="line">        minNum = backward</span><br><span class="line">    <span class="keyword">for</span> t <span class="keyword">in</span> intervals:</span><br><span class="line">        <span class="keyword">if</span> t[<span class="number">2</span>] == flip:</span><br><span class="line">            print(<span class="string">&quot;在位置&#123;&#125;到&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br><span class="line">    <span class="keyword">return</span> minNum</span><br></pre></td></tr></table></figure>
<p>注意别用caps.append(“END”)，这是在原来的数据上直接添加，当函数返回后数据还是被改变了。而caps = caps + [“END”]是创建一个新的列表，并不改变原来的列表。<br>现在来解决更难的问题：能不能在第一遍遍历的时候就确定命令的最小子集？<br>前面的程序还是遍历了两遍才得到命令序列的。这个我真想不出来，下面是书中的答案。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 一遍遍历的程序</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pleaseConformOnepass</span>(<span class="params">caps</span>):</span></span><br><span class="line">    caps = caps + [caps[<span class="number">0</span>]]</span><br><span class="line">    minNum = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="built_in">len</span>(caps)):</span><br><span class="line">        <span class="keyword">if</span> caps[i] != caps[i-<span class="number">1</span>]:</span><br><span class="line">            <span class="keyword">if</span> caps[i] != caps[<span class="number">0</span>]:</span><br><span class="line">                print(<span class="string">&quot;位置在&quot;</span>, i)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">&quot;到&quot;</span>, i-<span class="number">1</span>, <span class="string">&quot;的人，翻转你的帽子!&quot;</span>)</span><br><span class="line">                minNum += <span class="number">1</span></span><br><span class="line">    <span class="keyword">return</span> minNum</span><br></pre></td></tr></table></figure>
<p>原理是两个方向的帽子的区间数只相差1，如果第一个人的帽子是一个方向，该方向的区间数绝不会比另一个方向上的区间数小。（意思应该是最后的答案一定是翻转跟第一个人帽子方向相反的人的帽子）<br>上面的程序用与第一个人帽子方向相同的方向来标记末尾。当第一次碰到与第一个人帽子方向相反的情况的时候，我们开始记录区间。这意味着我们实际上跳过了第一个区间。该程序的缺点是不好修改，另外也需要额外处理输入数据为空的情况。<br>所以高效的简洁的程序往往隐藏了更复杂的东西，你要看得出那些东西才能写得出来。<br>这个问题背后的动机是数据压缩，比如”WWWWWWWWWWWWWBBWWWWWWWWWWWWBBBBB”可以压缩为“13W2B12W5B”，“WBWBWBWBWB”照此算法“压缩”为“1W1B1W1B1W1B1W1B1W1B”，然而更好的算法会压缩为”5(WB)”。<br>练习<br>1.对于最后一个区间只有一个元素的情况，会输出“在位置11到11的人，翻转你的帽子 ”，修改程序使其输出为”在位置11的人，翻转你的帽子 “。<br>改成</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> t[<span class="number">0</span>] != t[<span class="number">1</span>]:</span><br><span class="line">                print(<span class="string">&quot;在位置&#123;&#125;到&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">&quot;在位置&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br></pre></td></tr></table></figure>
<p>即可。<br>2.修改一次遍历的程序，像练习1一样输出更自然的结果，并且确保输入空列表不会崩溃。<br>在开始增加判断并像练习一一样输出修改即可。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 一遍遍历的程序,根据练习2修改版</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pleaseConformOnepass2</span>(<span class="params">caps</span>):</span></span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(caps) == <span class="number">0</span>:</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">    caps = caps + [caps[<span class="number">0</span>]]</span><br><span class="line">    minNum = <span class="number">0</span></span><br><span class="line">    start = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="built_in">len</span>(caps)):</span><br><span class="line">        <span class="keyword">if</span> caps[i] != caps[i-<span class="number">1</span>]:</span><br><span class="line">            <span class="keyword">if</span> caps[i] != caps[<span class="number">0</span>]:</span><br><span class="line">                start = i</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                <span class="keyword">if</span> start != i-<span class="number">1</span>:</span><br><span class="line">                    print(<span class="string">&quot;位置在&quot;</span>, start, <span class="string">&quot;到&quot;</span>, i-<span class="number">1</span>, <span class="string">&quot;的人，翻转你的帽子!&quot;</span>)</span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    print(<span class="string">&quot;位置在&quot;</span>, start,  <span class="string">&quot;的人，翻转你的帽子!&quot;</span>)</span><br><span class="line">                minNum += <span class="number">1</span></span><br><span class="line">    <span class="keyword">return</span> minNum</span><br></pre></td></tr></table></figure>
<p>练习3.假设有一些戴“奇异”帽子的人在队列中，以”H”标记，修改程序，跳过这些人，输出正确的命令。<br>统计的时候直接忽略”H”就行了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 练习三，增加&quot;H&quot;帽子的人，忽略</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pleaseConform3</span>(<span class="params">caps</span>):</span></span><br><span class="line">    start = forward = backward = <span class="number">0</span></span><br><span class="line">    intervals = []</span><br><span class="line">    <span class="comment"># 在数据末尾增加末尾标志</span></span><br><span class="line">    caps = caps + [<span class="string">&quot;END&quot;</span>]</span><br><span class="line">    n = <span class="built_in">len</span>(caps)</span><br><span class="line">    minNum = n</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, n):</span><br><span class="line">        <span class="comment"># 帽子方向变了，区间改变</span></span><br><span class="line">        <span class="keyword">if</span> caps[start] != caps[i]:</span><br><span class="line">            intervals.append((start, i-<span class="number">1</span>, caps[start]))</span><br><span class="line">            <span class="keyword">if</span> caps[i-<span class="number">1</span>] == <span class="string">&quot;F&quot;</span>:</span><br><span class="line">                forward += <span class="number">1</span></span><br><span class="line">            <span class="keyword">elif</span> caps[i-<span class="number">1</span>] == <span class="string">&quot;B&quot;</span>:</span><br><span class="line">                backward += <span class="number">1</span></span><br><span class="line">            start = i</span><br><span class="line">    <span class="keyword">if</span> forward &lt; backward:</span><br><span class="line">        flip = <span class="string">&quot;F&quot;</span></span><br><span class="line">        minNum = forward</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        flip = <span class="string">&quot;B&quot;</span></span><br><span class="line">        minNum = backward</span><br><span class="line">    <span class="keyword">for</span> t <span class="keyword">in</span> intervals:</span><br><span class="line">        <span class="keyword">if</span> t[<span class="number">2</span>] == flip:</span><br><span class="line">            <span class="keyword">if</span> t[<span class="number">0</span>] != t[<span class="number">1</span>]:</span><br><span class="line">                print(<span class="string">&quot;在位置&#123;&#125;到&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">&quot;在位置&#123;&#125;的人，翻转你的帽子&quot;</span>.<span class="built_in">format</span>(t[<span class="number">0</span>], t[<span class="number">1</span>]))</span><br><span class="line">    <span class="keyword">return</span> minNum</span><br></pre></td></tr></table></figure>
<p>练习4.写一个one pass压缩和解压程序。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 练习4 压缩和解压程序</span></span><br><span class="line"><span class="comment"># 压缩</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">compress</span>(<span class="params">words</span>):</span></span><br><span class="line">    str_list = <span class="built_in">list</span>(words)</span><br><span class="line">    str_list.append(str_list[<span class="number">0</span>])</span><br><span class="line">    start = <span class="number">0</span></span><br><span class="line">    code = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="built_in">len</span>(str_list)):</span><br><span class="line">        <span class="keyword">if</span> str_list[start] != str_list[i]:</span><br><span class="line">            code.append((start, i-<span class="number">1</span>, str_list[start]))</span><br><span class="line">            start = i</span><br><span class="line">    result = []</span><br><span class="line">    <span class="keyword">for</span> t <span class="keyword">in</span> code:</span><br><span class="line">        a = t[<span class="number">0</span>]</span><br><span class="line">        b = t[<span class="number">1</span>]</span><br><span class="line">        w = t[<span class="number">2</span>]</span><br><span class="line">        length = b-a+<span class="number">1</span></span><br><span class="line">        result.append(<span class="built_in">str</span>(length))</span><br><span class="line">        result.append(w)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;&quot;</span>.join(result)</span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line"><span class="comment"># 解压缩</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">decompress</span>(<span class="params">code</span>):</span></span><br><span class="line">    result = []</span><br><span class="line">    num = []</span><br><span class="line">    char = <span class="string">&quot;&quot;</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(code)):</span><br><span class="line">        <span class="keyword">if</span> code[i].isalpha() == <span class="literal">False</span>:</span><br><span class="line">            num.append(code[i])</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            nums = <span class="built_in">int</span>(<span class="string">&quot;&quot;</span>.join(num))</span><br><span class="line">            num = []</span><br><span class="line">            result.append(code[i]*nums)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;&quot;</span>.join(result)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 练习四</span></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    s = <span class="string">&quot;BWWWWWBWWWWWWWWWWWAAKKGGP&quot;</span></span><br><span class="line">    code = compress(s)</span><br><span class="line">    print(<span class="string">&quot;原字符串为:&quot;</span>, s)</span><br><span class="line">    print(<span class="string">&quot;压缩后的字符串为:&quot;</span>, code)</span><br><span class="line">    ds = decompress(code)</span><br><span class="line">    print(<span class="string">&quot;解压后的字符串为:&quot;</span>, ds)</span><br></pre></td></tr></table></figure>
<p>本章全部代码 <a target="_blank" rel="noopener" href="https://github.com/zwdnet/MyQuant/blob/master/44/01/ycac.py">https://github.com/zwdnet/MyQuant/blob/master/44/01/ycac.py</a><br>再去看看视频。打算把21个问题都像这么来一遍。主要锻炼自己的编程能力。</p>
<p>我发文章的三个地方，欢迎大家在朋友圈等地方分享，欢迎点“在看”。<br>我的个人博客地址：<a href="https://zwdnet.github.io/">https://zwdnet.github.io</a><br>我的知乎文章地址： <a target="_blank" rel="noopener" href="https://www.zhihu.com/people/zhao-you-min/posts">https://www.zhihu.com/people/zhao-you-min/posts</a><br>我的微信个人订阅号：赵瑜敏的口腔医学学习园地</p>
<p><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg"></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>欢迎打赏！感谢支持！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/mm_facetoface_collect_qrcode_1542944836634.png" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/1542944857770.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Python/" rel="tag"># Python</a>
          
            <a href="/tags/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" rel="tag"># 量化投资</a>
          
            <a href="/tags/%E7%BC%96%E7%A8%8B%E9%9A%BE%E9%A2%98/" rel="tag"># 编程难题</a>
          
            <a href="/tags/MIT/" rel="tag"># MIT</a>
          
            <a href="/tags/%E5%88%97%E8%A1%A8/" rel="tag"># 列表</a>
          
            <a href="/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/" rel="tag"># 字符串</a>
          
            <a href="/tags/%E6%95%B0%E6%8D%AE%E5%8E%8B%E7%BC%A9/" rel="tag"># 数据压缩</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/04/30/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B045%E2%80%94%E2%80%94%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%934-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" rel="next" title="量化投资学习笔记45——基本数据结构算法总结4 动态规划">
                <i class="fa fa-chevron-left"></i> 量化投资学习笔记45——基本数据结构算法总结4 动态规划
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/05/02/%E4%BD%A0%E4%BC%9A%E5%A4%87%E7%89%99%E5%90%97%E2%80%94%E2%80%94%E5%89%8D%E7%89%99%E5%85%A8%E5%86%A0%E7%89%99%E4%BD%93%E9%A2%84%E5%A4%87%EF%BC%88%E7%BB%AD%EF%BC%89/" rel="prev" title="你会备牙吗——前牙全冠牙体预备（续）">
                你会备牙吗——前牙全冠牙体预备（续） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80MTA2Mi8xNzU4Nw=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%20%7C%7C%20archive">
              
                  <span class="site-state-item-count">452</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">29</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">544</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">本站版权归赵瑜敏所有，如欲转载请与本人联系。</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">1225.8k</span>
  
</div>









<div>
  <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1275447216'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1275447216%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
</div>

        







  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1275447216&web_id=1275447216" language="JavaScript"></script>
  </div>



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

  
</body>
</html>
